/*
 * phdr.h
 *
 *  Created on: Sep 9, 2012
 *      Author: aortegag
 */

#ifndef PHDR_H_
#define PHDR_H_

#include "elf_t.h"

/**
 *  \brief Checks the ELF header if there is a Program Header table and
 *  and allocates e_phentsize*e_phnum bytes for the table.
 *
 *  \retval A pointer to an array for the program header table or 0 when there
 *  is no table.
 */
Elf64_Phdr *allocate_program_header_table(const Elf64_Ehdr *ehdr);

/**
 * \brief Reads the program header table from the file descriptor and saves it
 * into the phdr Section header table.
 *
 * \note This function assumes file pointed to by fp is already opened and that
 * phdr already points to a buffer of (ehdr->e_phentsize*ehdr->e_phnum) bytes.
 *
 * \param[in] fp File pointer to a valid file.
 * \param[in] ehdr ELF header table structure
 * \param[out] phdr New Program header table allocated.
 *
 * \retval Elf code
 */
elf_code_t read_program_header_table(FILE *fd, const Elf64_Ehdr *ehdr, Elf64_Phdr *phdr);


//! \brief Pretty prints the Program Header table
void	pretty_print_phdr(const Elf64_Ehdr *ehdr, const Elf64_Phdr *phdr);

#endif /* PHDR_H_ */
